//
//  BiPurchaseYanshouViewController.m
//  TrunkIndustryManageSystem
//
//  Created by WT_lyy on 15/4/28.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//

#import "BiPurchaseYanshouViewController.h"

#import "BiMenuListView1.h"
#import "BiPurchaseCarInfoView.h"

#import "BiPurchaseYanshouEntity.h"
#import "BiPurChaseCarInfoEntity.h"

#import "BiPurchaseOilTankInfoView.h"
#import "BiPurchaseFlatTruckInfoView.h"
#import "BiPurchaseMixerTruckInfoView.h"


static CGRect frame;
@interface BiPurchaseYanshouViewController()<UITextFieldDelegate,BiMenuListView1Delegate,UIImagePickerControllerDelegate, UINavigationControllerDelegate,UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate>{


    BiPurchaseCarInfoView *_viewCarinfo;
    BiMenuListView1 * menuListView;
    
    UITableView * _tableView;
    
    IBOutlet UIView *_headView;
    
    IBOutlet UIView *_bottomView;
    
    NSInteger imgType;
    
    NSMutableDictionary * _imageUrlDic; //key 为imgtype指示， value为图片url数组

    
    NSMutableDictionary * _netImageBtnDic; //key 为cell指示， value为cell中网络照片按钮数组
    
    NSMutableDictionary * _locImageBtnDic;  //key 为cell指示， value为cell中本地照片按钮数组
    
    
    BOOL isFirstFresh; // 是否第一次加载cell图片
    
    NSInteger countIm;  //图片需上传计数
    NSInteger countUp; //图片上传完成计数
    
    BOOL isSave;
    
    NSInteger  _indexCell;// 纪录当前cell索引
    
    NSInteger  _index;// 纪录当前cell图片按钮索引
}


@property (weak, nonatomic) IBOutlet UIButton *btnStoreRoom;
@property (weak, nonatomic) IBOutlet UILabel *labSaleState;
@property (weak, nonatomic) IBOutlet UILabel *labVin;
@property (weak, nonatomic) IBOutlet UILabel *labStayPlace;
@property (weak, nonatomic) IBOutlet UILabel *labOperator;
@property (weak, nonatomic) IBOutlet UILabel *labCreatTime;
@property (weak, nonatomic) IBOutlet UITextField *_textfPerformance;
@property (nonatomic,strong)     NSArray * textArr;

@end

@implementation BiPurchaseYanshouViewController

- (id)init{
    
    self = [super init];
    
    if (self) {
        isSave = NO;
        
        isFirstFresh = YES;
        _imageUrlDic = [NSMutableDictionary new];
        
        _netImageBtnDic = [NSMutableDictionary new];
        
        _locImageBtnDic = [NSMutableDictionary new];
        
        _textArr  = [NSArray arrayWithObjects:@"验收清单",@"发动机号",@"发动机铭牌",@"整车铭牌",@"左前45度",@"左后45度",@"右前45度",@"右后45度",@"V I N",nil];
        countIm = 0;
        countUp = 0;
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavBarTitle:@"验车入库"];
    
    [self setNavBarWithHidden:NO];
    
    [self setNavBackBtn];

    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
    
    [self.view addGestureRecognizer:tap];
    
    [self _inittable];

    [self dataFill];
}


- (void)_inittable{
    
    for (NSDictionary * imgDic  in self.centity.photos) {
        
        NSMutableArray * tempArr = _imageUrlDic[imgDic[@"imgType"]];
        
        if (!tempArr) {
            
            tempArr = [NSMutableArray array];
            
            [tempArr addObject:imgDic];
            
            [_imageUrlDic setObject:tempArr forKey:imgDic[@"imgType"]];
        }else{
            [tempArr addObject:imgDic];
        }
    }

    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, [self viewTop], MAIN_SCREEN_WIDTH, MAIN_SCREEN_HEIGHT-[self viewTop]-40)];
    
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

- (void)dataFill{
    
    if (!_viewCarinfo) {
        _viewCarinfo = [[[NSBundle mainBundle] loadNibNamed:@"BiPurchaseCarInfoView" owner:self options:nil] firstObject];
    }
    
    if(self.centity.flatEntity){
        BiPurchaseFlatTruckInfoView * flatView = [[[NSBundle mainBundle] loadNibNamed:@"BiPurchaseFlatTruckInfoView" owner:self options:nil] firstObject];
        
        UIView * headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MAIN_SCREEN_WIDTH, 680)];
        [headView addSubview:_viewCarinfo];
        
        flatView.frame = CGRectMake(0, 234, MAIN_SCREEN_WIDTH, 346);
        
        [headView addSubview:flatView];
        
        _headView.frame = CGRectMake(0, 580, MAIN_SCREEN_WIDTH, 100);
        [headView addSubview:_headView];
        _tableView.tableHeaderView = headView;
        [flatView setFlatDataFill:self.centity.flatEntity];
        
    }else if (self.centity.stinEntity){
        
        BiPurchaseMixerTruckInfoView * mixeView = [[[NSBundle mainBundle] loadNibNamed:@"BiPurchaseMixerTruckInfoView" owner:self options:nil] firstObject];
        
        UIView * headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MAIN_SCREEN_WIDTH, 610)];
        [headView addSubview:_viewCarinfo];
        
        mixeView.frame = CGRectMake(0, 234, MAIN_SCREEN_WIDTH, 276);
        
        [headView addSubview:mixeView];
        
        _headView.frame = CGRectMake(0, 510, MAIN_SCREEN_WIDTH, 100);
        [headView addSubview:_headView];
        _tableView.tableHeaderView = headView;
        [mixeView setMixeDataFill:self.centity.stinEntity];
        
    }else if (self.centity.oilEntity){
        
        BiPurchaseOilTankInfoView * oilView = [[[NSBundle mainBundle] loadNibNamed:@"BiPurchaseOilTankInfoView" owner:self options:nil] firstObject];
        
        UIView * headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MAIN_SCREEN_WIDTH, 534)];
        [headView addSubview:_viewCarinfo];
        
        oilView.frame = CGRectMake(0, 234, MAIN_SCREEN_WIDTH, 240);
        
        [headView addSubview:oilView];
        
        _headView.frame = CGRectMake(0, 434, MAIN_SCREEN_WIDTH, 100);
        [headView addSubview:_headView];
        _tableView.tableHeaderView = headView;
        [oilView setOilDataFill:self.centity.oilEntity];
        
    }else{
    
        UIView * headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MAIN_SCREEN_WIDTH, 334)];
        [headView addSubview:_viewCarinfo];
        _headView.frame = CGRectMake(0, 234, MAIN_SCREEN_WIDTH, 100);
        [headView addSubview:_headView];
        _tableView.tableHeaderView = headView;
    }
    
    
    _tableView.tableFooterView = _bottomView;
    
    BiPurChaseCarInfoEntity * carInfo = self.centity.carEntity;
    
    [_viewCarinfo setCarInfo:carInfo withOrderNum:self.centity.systemNumber];
    
    self.labSaleState.text = carInfo.saleStatus;
    
    self.labCreatTime.text = self.centity.createTime;
    
    self.labOperator.text = [BiUserEntity sharedInstance].name;
    
    self.labVin.text = carInfo.vin;
    
    self.labStayPlace.text = carInfo.parkAddress;
    
    self._textfPerformance.text = self.centity.checkRukuPerformance;
    
     [self.btnStoreRoom setTitle:carInfo.storeRoomName forState:UIControlStateNormal];
}


#pragma  -mark Btn Action
- (IBAction)btnSaveCheck:(UIButton *)sender {
    
    if (1 == sender.tag) {//save
        
        NSString * userId = nil;
        
        if ([self.centity.checkRukuUserId intValue] == 0||self.centity.checkRukuUserId.length==0) {
           
            userId = [BiUserEntity sharedInstance].userid;
        }else{
        
            userId = self.centity.checkRukuUserId;
        }

        NSDictionary * paraDic = [NSDictionary dictionaryWithObjectsAndKeys:self.centity.e_id,@"id",
                                  userId,@"checkRukuUserId",
                                  [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:mm"],@"checkRukuCreateTime",
                                  self._textfPerformance.text,@"checkRukuPerformance",
                                 self.centity.carEntity.storeRoomId,@"storeRoomId",
                                  self.centity.carEntity.parkAddress,@"parkAddress",
                                 self.centity.carId,@"carId",nil];
        
        [[BiNetEngine shareInstance] requestPurchaseCarRukuSave:self paraDict:paraDic];
        
        
    }else if (2 == sender.tag){
    //check
        NSDictionary * paraDic = [NSDictionary dictionaryWithObjectsAndKeys:self.centity.orderId,@"id",

                                  @"1",@"status",nil];
        
        [[BiNetEngine shareInstance] requestPurchaseCarRukuCheck:self paraDict:paraDic];
        
    }
    //add imgae up request
    for (NSString *keystr in [_locImageBtnDic allKeys]) {
        
        NSArray * locBtnarr = _locImageBtnDic[keystr];
        
        for (int i = 0;i < locBtnarr.count ;i++ ) {
            
            NSString * filename = [NSString stringWithFormat:@"%u",arc4random()];
            
            UIButton * butn = locBtnarr[i];
            
            NSDictionary * paraDicIm = [NSDictionary dictionaryWithObjectsAndKeys:self.centity.e_id,@"id",keystr,@"imgType",filename,@"fileName", nil];
            
            [[BiNetEngine shareInstance] requestPurchaseYanshouImage:self withImge:[butn currentBackgroundImage] paraDic:paraDicIm];
        }
        
    }
    
    [self asyshowHUDView:WAITING CurrentView:self];
}


- (IBAction)btnStoreRoomClick:(id)sender {
    
    
    [[BiNetEngine shareInstance] requestPurchaseStoreRoomList:self paraDict:nil];
    
    
//    UIButton * buttn = (UIButton *)sender;
//    
//    NSArray * roomArr = self.centity.storeRoomNames;
//    if (!menuListView) {
//        
//        menuListView = [[BiMenuListView1 alloc] initWithFrame:CGRectMake(self.view.window.frame.origin.x, 0, self.view.window.frame.size.width, self.view.window.frame.size.height)];
//        
//    }
//    menuListView.delegate = self;
//    
//    Float32 listY = self.btnStoreRoom.frame.origin.y+self.btnStoreRoom.frame.size.height+[self.btnStoreRoom superview].frame.origin.y+60 - _tableView.contentOffset.y;
//    
//    [menuListView setNameArray:roomArr viewX:buttn.frame.origin.x topY:listY width:buttn.frame.size.width];
//    
//    [self.view.window addSubview:menuListView];
}

- (void)btnCameroClick:(UIButton *)sender {
    
    imgType = sender.tag - 20;
    
    NSArray * netimBtnArr = _netImageBtnDic[[NSString stringWithFormat:@"%d",(int)imgType]];
    
    NSArray * locimBtnArr = _locImageBtnDic[[NSString stringWithFormat:@"%d",(int)imgType]];
    
    if ((locimBtnArr.count+netimBtnArr.count) == 3) {
        
        [self showMessage:@"亲，最多三张图片！"];
        
        return;
    }
    
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"相机功能不可用" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alertView show];
        return;
    }
    
    UIImagePickerController * picker = [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:nil];
    
}

- (void)btnImageClcik:(UIButton *)button{
    
    
    UIActionSheet* mySheet = [[UIActionSheet alloc]
                              initWithTitle:nil
                              delegate:self
                              cancelButtonTitle:@"取消"
                              destructiveButtonTitle:@"删除图片"
                              otherButtonTitles:@"查看大图", nil];
    [mySheet showInView:self.view];
    
    mySheet.tag = button.tag;
    
}



#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{

    NSInteger indexCell = actionSheet.tag%100/10;
    
    NSInteger index = actionSheet.tag%10;
    
    _indexCell = indexCell;
    
    _index = index;
    
    switch (buttonIndex)
    {
        case 0:
        {  //删除图片
            
            if (actionSheet.tag < 200) { //网络图片
                
                //网络请求
                NSMutableArray * tempArr = _imageUrlDic[[NSString stringWithFormat:@"%d",(int)indexCell]];
                
                NSDictionary * fileDic = tempArr[index];
                
                NSString * filename = [fileDic[@"imgUrls"] firstObject];
                
                NSDictionary * deleDic =[NSDictionary dictionaryWithObjectsAndKeys:self.centity.e_id,@"id",[filename lastPathComponent],@"filePath",[NSNumber numberWithInteger:indexCell],@"imgType", nil];
                
                [[BiNetEngine shareInstance] requestPuchaseRefitImageDel:self paraDic:deleDic];
                
                [self asyshowHUDView:WAITING CurrentView:self];
                
                [tempArr removeObjectAtIndex:index];
                
                
            }else{//本地拍照
                
                NSMutableArray * btnArr = _locImageBtnDic[[NSString stringWithFormat:@"%d",(int)indexCell]];
                
                UIButton * btn = btnArr[index];
                
                [btn removeFromSuperview];
                
                [btnArr removeObjectAtIndex:index];
                
                for (int i = index; i< btnArr.count;i++) {
                    
                    UIButton * butn = btnArr[i];
                    
                    butn.tag --;
                    
                    butn.frame = CGRectMake(butn.frame.origin.x-butn.frame.size.width-5, butn.frame.origin.y, butn.frame.size.width, butn.frame.size.height);
                }
                
                NSIndexPath * path = [NSIndexPath indexPathForRow:indexCell inSection:0];
                
                NSArray * patArr = @[path];
                [_tableView reloadRowsAtIndexPaths:patArr withRowAnimation:UITableViewRowAnimationNone];
            }
            
  
        }
            break;
        case 1:
        {  // 查看大图
            //判断是网络还是本地拍摄图
            
            if (actionSheet.tag < 200) { //网络图片
                
                UIButton * btn = _netImageBtnDic[[NSString stringWithFormat:@"%d",(int)indexCell]][index];
                [BiUtil pusuToImageVc:self image:[btn currentBackgroundImage] title:_textArr[indexCell]];
            }else{//本地拍照
                
                UIButton * btn = _locImageBtnDic[[NSString stringWithFormat:@"%d",(int)indexCell]][index];
                
                [BiUtil pusuToImageVc:self image:[btn currentBackgroundImage] title:_textArr[indexCell]];
            }
            
        }
            break;
        default:
            break;
    }
}



#pragma -mark UitabeViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    if (isFirstFresh) {
        NSArray * imgArr = _imageUrlDic[[NSString stringWithFormat:@"%d",(int)indexPath.row]];
        
        if (imgArr && imgArr.count >0) {
            
            
            return 55 + (MAIN_SCREEN_WIDTH-20)/3;
        }
    }else{
    
        NSArray * locArr = _locImageBtnDic[[NSString stringWithFormat:@"%d",(int)indexPath.row]];
        NSArray * netArr = _netImageBtnDic[[NSString stringWithFormat:@"%d",(int)indexPath.row]];
        NSInteger count = 0;
        
        if (locArr) {
            count += locArr.count;
        }
        
        if (netArr) {
            count += netArr.count;
        }
        
        if (count>0) {
            return 55 + (MAIN_SCREEN_WIDTH-20)/3;
        }
    }

    
    return 45;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

#pragma -mark UitabeViewDatasource

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 9;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * myIdentify = @"ImageCell";

    UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myIdentify];
    
    UILabel * lab = GET_LABEL(CGRectMake(10, 15, 100, 15), 14, NO, [UIColor blackColor], NSTextAlignmentLeft);
    
    [cell addSubview:lab];
    
    UIButton * button = GET_BUTTON(CGRectMake(MAIN_SCREEN_WIDTH - 100, 10, 80, 25), 14, NO, UIColorFromRGB(ORANGE_COLOR_VALUE));
    [cell addSubview:button];
    button.tag = indexPath.row+20;
    button.layer.borderColor = UIColorFromRGB(ORANGE_COLOR_VALUE).CGColor;
    button.layer.borderWidth =1;
    button.layer.cornerRadius = 3;
    [button setTitle:@"上传拍照" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(btnCameroClick:) forControlEvents:UIControlEventTouchUpInside];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    [self imageViewForCell:cell index:indexPath];
    
    cell.backgroundColor = [UIColor whiteColor];
    
    
    if (0 == indexPath.row) {
        cell.backgroundColor = UIColorFromRGB(0xe5e5e5);
        
    }
    lab.text = _textArr[indexPath.row];
    
    return cell;
}


- (void)imageViewForCell:(UITableViewCell *)cell index:(NSIndexPath *)indexPath{

    if (isFirstFresh) {
        NSArray * imgArr = _imageUrlDic[[NSString stringWithFormat:@"%d",(int)indexPath.row]];
        
        for (int i = 0; i < imgArr.count; i ++) {
            
            NSDictionary * dic = imgArr[i];
            
            UIButton * imViewbtn = [[UIButton alloc] initWithFrame:CGRectMake(5*(i+1)+(MAIN_SCREEN_WIDTH-20)/3*i, 50, (MAIN_SCREEN_WIDTH-20)/3, (MAIN_SCREEN_WIDTH-20)/3)];
            
            [imViewbtn addTarget:self action:@selector(btnImageClcik:) forControlEvents:UIControlEventTouchUpInside];
            imViewbtn.tag = 100+indexPath.row*10 + i;
            
            [cell addSubview:imViewbtn];
            imViewbtn.backgroundColor =[UIColor yellowColor];
            
            [imViewbtn reloadImage:[dic[@"imgUrls"] firstObject]];
        }
    }else{//绘制本地照片按钮
    
        NSArray * netBtnArr = _netImageBtnDic[[NSString stringWithFormat:@"%d",(int)indexPath.row]];
        NSArray * locBtnArr = _locImageBtnDic[[NSString stringWithFormat:@"%d",(int)indexPath.row]];
        
        for (int i = 0; i < netBtnArr.count; i ++) {
            
            UIButton * netbtn = netBtnArr[i];
            
            [cell addSubview:netbtn];
        }
        
        for (int i = 0; i < locBtnArr.count; i ++) {
            
            UIButton * netbtn = locBtnArr[i];
            
            [cell addSubview:netbtn];
        }
    }

    
  
}

#pragma -mark MenuListView1Delegate
- (void)onMenuListView1Select:(int)index{

    if (menuListView.superview) {
        
        [menuListView removeFromSuperview];
    }
    [self.btnStoreRoom setTitle:self.centity.storeRoomNames[index] forState:UIControlStateNormal];
}

#pragma -amrk UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textView{
    frame= _tableView.frame;
    
    _tableView.frame = CGRectMake(0, _tableView.frame.origin.y - 216, _tableView.frame.size.width, _tableView.frame.size.height);
    
}


- (void)textFieldDidEndEditing:(UITextField *)textView{
    
    [textView resignFirstResponder];
    
    _tableView.frame = frame;
    
}

- (void)tapClick{
    
    [self._textfPerformance resignFirstResponder];
}

#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [picker dismissViewControllerAnimated:YES completion:nil];
    image = [BiUtil scaleToSize:image size:CGSizeMake(200, 200)];
    
    NSArray * _netBtnArr = _netImageBtnDic[[NSString stringWithFormat:@"%d",(int)imgType]];
    
    NSInteger count = 0;
    if (_netBtnArr) {
        count = _netBtnArr.count;
    }
    NSMutableArray * locBtnArr = [_locImageBtnDic objectForKey:[NSString stringWithFormat:@"%d",(int)imgType]];
    
    if (locBtnArr) {
        count +=locBtnArr.count;
    }
    
    if (count >= 3) {
        
        [self showMessage:@"亲，最多三张图片！"];
        
        return;
    }

    
    NSInteger loaccount = 0;
    
    if (locBtnArr) {
        loaccount = locBtnArr.count;
    }
    
    UIButton * imViewbtn = [[UIButton alloc] initWithFrame:CGRectMake(5*(count+1)+(MAIN_SCREEN_WIDTH-20)/3*count, 50, (MAIN_SCREEN_WIDTH-20)/3, (MAIN_SCREEN_WIDTH-20)/3)];
    
    [imViewbtn addTarget:self action:@selector(btnImageClcik:) forControlEvents:UIControlEventTouchUpInside];
    
    [imViewbtn setBackgroundImage:image forState:UIControlStateNormal];
    
    imViewbtn.tag =200+ imgType*10 + loaccount;
    
    if (!locBtnArr) {
        
        locBtnArr = [[NSMutableArray alloc] init];
        
        [locBtnArr addObject:imViewbtn];
        
        [_locImageBtnDic setObject:locBtnArr forKey:[NSString stringWithFormat:@"%d",(int)imgType]];
    
    }else{
    
        [locBtnArr addObject:imViewbtn];
    }
    
    
    isFirstFresh = NO;
    
    
    NSIndexPath * path = [NSIndexPath indexPathForRow:imgType inSection:0];
    
    NSArray * patArr = @[path];
    [_tableView reloadRowsAtIndexPaths:patArr withRowAnimation:UITableViewRowAnimationNone];
    
   // UITableViewCell * cell  = [_tableView cellForRowAtIndexPath:path];
    
   // [cell addSubview:imViewbtn];
    
    countIm++;
    
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}


#pragma -mark Net Delegate
- (void)onNetEngineResponse:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    
    NSDictionary * entity_ = (NSDictionary *)entity;
    
    //[self showMessage:entity_[@"result_info"]];
    
    if ([entity_[@"response_status"] integerValue] != 200) {
        [self removeHUDView:self];
        return;
        
    }
    
    switch (tag) {

        case NET_GET_PURCHASE_CARRUKU_CHECK:
        case NET_GET_PURCHASE_CARRUKU_SAVE:
            isSave = YES;
            break;
            
            
        case NET_GET_PURCHASE_YANSHOU_IMAGE:
            countUp++;
            break;
        case NET_GET_PURCHASE_STOREROOM_LIST:{

            NSArray *arr = entity_[@"data"];
            
            if (!menuListView) {
                
                menuListView = [[BiMenuListView1 alloc] initWithFrame:CGRectMake(self.view.window.frame.origin.x, 0, self.view.window.frame.size.width, self.view.window.frame.size.height)];
                
            }
            menuListView.delegate = self;
            
            Float32 listY = self.btnStoreRoom.frame.origin.y+self.btnStoreRoom.frame.size.height+[self.btnStoreRoom superview].frame.origin.y+60 - _tableView.contentOffset.y;
            
            [menuListView setNameArray:nil viewX:self.btnStoreRoom.frame.origin.x topY:listY width:self.btnStoreRoom.frame.size.width];
            
            [self.view.window addSubview:menuListView];
        }
            break;
        case NET_GET_PURCHASE_REFIT_IMAGEDEL:{
        
            
            NSMutableArray * netbtnArr = _netImageBtnDic[[NSString stringWithFormat:@"%d",(int)_indexCell]];
            UIButton * nowbtn = netbtnArr[_index];
            
            [nowbtn removeFromSuperview];
            
            [netbtnArr removeObjectAtIndex:_index];
            
            
            for (int i = _index; i< netbtnArr.count;i++) {
                
                UIButton * butn = netbtnArr[i];
                
                butn.tag --;
                
                butn.frame = CGRectMake(butn.frame.origin.x-butn.frame.size.width-5, butn.frame.origin.y, butn.frame.size.width, butn.frame.size.height);
            }
            
            NSMutableArray * locbtnArr = _locImageBtnDic[[NSString stringWithFormat:@"%d",(int)_indexCell]];
            for (int i = 0; i< locbtnArr.count;i++) {
                
                UIButton * butn = locbtnArr[i];
                
                butn.tag --;
                
                butn.frame = CGRectMake(butn.frame.origin.x-butn.frame.size.width-5, butn.frame.origin.y, butn.frame.size.width, butn.frame.size.height);
            }
            
            NSIndexPath * path = [NSIndexPath indexPathForRow:_indexCell inSection:0];
            
            NSArray * patArr = @[path];
            [_tableView reloadRowsAtIndexPaths:patArr withRowAnimation:UITableViewRowAnimationNone];
            
            [self removeHUDView:self];

        }
        default:
            break;
    }
    
    if (isSave && (countUp == countIm)) {
        [self removeHUDView:self];
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}
- (void)onNetEngineResponseFail:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    [self removeHUDView:self];
    
}

@end
